layui.use(['jquery','layer','table','form','laydate'],function() {
    var $ = layui.jquery;
    var layer = layui.layer;
    var table = layui.table;
    var form = layui.form;
    var laydate = layui.laydate;
    //绑定时间
    laydate.render({
        elem: '#graduationDate',
        type: 'datetime',
        trigger: 'click'
    })
    laydate.render({
        elem: '#entranceDate',
        type: 'datetime',
        trigger: 'click'
    })
    //状态回显
    var UserStatus = JSON.parse(localStorage.getItem("userStatus"));
    $("#status").val(UserStatus);
    form.render("select");

    //自定义表单验证规则
    form.verify({
        title: function(value){
            if(value.length < 5){
                return '标题至少得5个字符啊';
            }
        }, fname: function(value){
            if(value.length < 4){
                return '请输入至少4位的用户名';
            }
        }, contact: function(value){
            if(value.length < 4){
                return '内容请输入至少4个字符';
            }
        }
        ,phone: [/^1[3|4|5|7|8]\d{9}$/, '手机必须11位，只能是数字！']
        ,email: [/^[a-z0-9._%-]+@([a-z0-9-]+\.)+[a-z]{2,4}$|^1[3|4|5|7|8]\d{9}$/, '邮箱格式不对']
        ,integration: [/^100$|^[123456789][0-9]$|^[0-9]$/,'请输入数字0~100']
    });

    //监听提交
    form.on('submit(demo1)', function(data){
        updateUser();
        return true;
    });

    var userId = localStorage.getItem("userId");
    //修改用户 确定
    function updateUser(){
        var param = {
            'userId':userId,
            'nickname':$("input[name=nickname]").val(),
            'studyDate':$("input[name=studyDate]").val(),
            'idCard':$("input[name=idCard]").val(),
            'freestyle':$("input[name=freestyle]").val(),
            'status':$("#status").val(),
            'remarks':$("#remarks").val()
        }
        $.ajax({//修改前端用户
            url:"/user/editBeforeUser",
            data:param,
            type:'post',
            dataType:'json',
            success:function (data) {
                var params = {
                    'userId':userId,
                    'profession':$("input[name=profession]").val(),
                    'entranceDate':$("input[name=entranceDate]").val(),
                    'graduationDate':$("input[name=graduationDate]").val(),
                    'integration':$("input[name=integration]").val(),
                    'studyContent':$("input[name=studyContent]").val(),
                }
                $.ajax({//修改进思用户
                    url:"/user/editJinsiUser",
                    data:params,
                    type:'post',
                    dataType:'json',
                    success:function (data) {
                        layer.msg("修改成功");
                    }
                })
            }
        })
        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
        parent.layer.close(index); //再执行关闭
    }

    //取消 cancel
    $("#cancel").click(function () {
        //当你在iframe页面关闭自身时
        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
        parent.layer.close(index); //再执行关闭
    })
})